package datalayer;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.SQLException;

public class DataSaveIP extends DataConnection{

	private static DataSaveIP instance;

	public static DataSaveIP getInstance() {
		if (instance == null) {
			instance = new DataSaveIP();
		}
		return instance;
	}

	public void UpdateServerIP() throws UnknownHostException{
		String ip = InetAddress.getLocalHost().getHostAddress();
		String pcnaam = System.getProperty("user.name");

		String sql = "UPDATE server SET ip_address = '"+ ip +"', naam = '" + pcnaam +"' WHERE id = '1'";
		
		try{
			System.out.println(sql);
			stmt = conn.createStatement();
			stmt.executeUpdate(sql);
		}
		catch(SQLException sqle){
			sqle.printStackTrace();
		}
	}

	public void SaveIP() throws UnknownHostException{
		openConn();
		UpdateServerIP();
		closeConn();
	}

}